<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>入库单审核</title>
<%@include file="/WEB-INF/jsp/include/easyui_1_5_3.jsp"%>
<script type="text/javascript" src="${path}/js/business/sysUnitInfoComboTree.js"></script>
<script type="text/javascript" src="${path}/js/business/kvComboBox.js"></script>
<script type="text/javascript" src="${path}/js/business/getData.js"></script>

<script type="text/javascript">
	//请求地址
	var url;
	//提示消息
	var mesTitle;
	
	//药品
	var physicData = '';
	physicData = ajax_json(path+'/psPhysicDict/getByJson',physicData);
	var ypggData = '';
	ypggData = ajax_json(path+'/sysDict/kvByType?pid=药品规格',ypggData);
	var ypdwData = '';
	ypdwData = ajax_json(path+'/sysDict/kvByType?pid=药品单位',ypdwData);
	var ypjxData = '';
	ypjxData = ajax_json(path+'/sysDict/kvByType?pid=药品剂型',ypjxData);
	var rklxData = '';
	rklxData = ajax_json(path+'/sysDict/kvByType?pid=入库类型',rklxData);
	
	//页面加载后执行
	$(function(){
// 		unitInfoComboTree('#unit_id_form',path+'/sysUnitInfo/getBy');
		kvComboBoxLoadData('#physic_in_sort_form',rklxData);
// 		kvComboBox('#physic_in_sort_form',path+'/sysDict/kvByType?pid=入库类型');
		kvComboBox('#method_of_payment_form',path+'/sysDict/kvByType?pid=付款方式');
// 		kvComboBox('#account_sign_form',path+'/sysDict/kvByType?pid=isno');
		
    });
	
	//添加用户信息
	function addPsPhysicInHead(){
// 		$('#dlg').dialog('open').dialog('refresh', path+'/psPhysicInHead/toAdd');
		$('#dlg').dialog('open').dialog('setTitle','新增');
		$('#fm').form('clear');
		url=path+"/psPhysicIn/add";
// 		url=path+"/psPhysicInHead/add";
		mesTitle = '新增成功';
	}
	
	//编辑用户信息
 	function editPsPhysicInHead(){
	 	var row = $('#datagrid').datagrid('getSelected');
	 	if (row){
	 		var id = row.id;
		 	$('#dlg').dialog('open').dialog('setTitle','编辑');
		 	$('#fm').form('load',row);
		 	url = path+"/psPhysicIn/modify?id="+id;
// 		 	url = path+"/psPhysicInHead/modify?id="+id;
		 	mesTitle = '编辑成功';
		 	
		 	loadDetails(row.inout_order_number);
	 	}else{
	 		$.messager.alert('提示', '请选择要编辑的记录！', 'error');
	 	}
	}
	//加载明细
	function loadDetails(order_number ){
	    var opts = $("#dg-details").datagrid("options");
	    opts.url = '${path}/psPhysicInDetail/datagrid';
	    $("#dg-details").datagrid("load", {
            "inout_order_number": order_number
        });
	}
 	
	//删除用信息
 	function deletePsPhysicInHead(){
	 	var row = $('#datagrid').datagrid('getSelected');
	 	if (row){
	 		var inout_order_number = row.inout_order_number;
		 	$('#dlg_delete').dialog('open').dialog('setTitle','审核');
		 	$('#fmdelete').form('load',row);
		 	url = path+"/psPhysicIn/examine?inout_order_number="+inout_order_number;
		 	mesTitle = '审核成功';
	 	}else{
	 		$.messager.alert('提示', '请选择要审核的记录！', 'error');
	 	}
	}
 	
	//保存添加、修改内容
	function savePsPhysicInHead(){
	
		if (endEditing()){
			if ($('#dg-details').datagrid('getChanges').length) {
				var inserted = $('#dg-details').datagrid('getChanges', 'inserted');
				var updated = $('#dg-details').datagrid('getChanges', 'updated');
				var deleted = $('#dg-details').datagrid('getChanges', 'deleted');
				$('#inserted').val(JSON.stringify(inserted));
				$('#updated').val(JSON.stringify(updated));
				$('#deleted').val(JSON.stringify(deleted));
			}
		}
	 	$('#fm').form('submit',{
		 	url: url,
		 	onSubmit: function(){
		 		return $(this).form('validate');
		 	},
			success: function(result){
				/* console.info(result); */
				var result = eval('('+result+')');
				if (result.success){
					$('#dg-details').datagrid('acceptChanges');
				 	$('#dlg').dialog('close'); 
				 	$('#datagrid').datagrid('reload'); 
				} else {
					 mesTitle = '新增失败';
				}
				$.messager.show({ 
					 title: mesTitle,
					 msg: result.msg
				});
			}
	 	});
	}
	
	//提交删除内容
	function savePsPhysicInHead_del(){
	 	$('#fmdelete').form('submit',{
		 	url: url,
		 	onSubmit: function(){
		 		return $(this).form('validate');
		 	},
			success: function(result){
				/* console.info(result); */
				var result = eval('('+result+')');
				if (result.success){
				 	$('#dlg_delete').dialog('close'); 
				 	$('#datagrid').datagrid('reload'); 
				} else {
					 mesTitle = '新增失败';
				}
				$.messager.show({ 
					 title: mesTitle,
					 msg: result.msg
				});
			}
	 	});
	}

	//快速查询
 	function searchPsPhysicInHeadQ(){
	 	$("#datagrid").datagrid("load", {
            "username": $('#search_username').val()
        });
	}
	
	//查询
 	function searchPsPhysicInHead(){
		$('#dlgsearch').dialog('open').dialog('setTitle','查询');
		$('#fmsearch').form('clear');
		url = path+"/user/searchUser";
		mesTitle = '查询成功';
	}
	
	//刷新
	function reload(){
		$('#datagrid').datagrid('reload'); 
	}
</script>

</head>
<body class="easyui-layout" fit="true">
	<div region="center" border="false" style="overflow: hidden;">
		<!-- 信息列表 title="管理" -->
		<table id="datagrid" class="easyui-datagrid" 
		    fit="true"
			url="${path}/psPhysicInHead/datagrid" 
			toolbar="#toolbar" 
			pagination="true"
			fitColumns="false" 
			singleSelect="true" 
			rownumbers="true"
			striped="true"
			border="false" 
			nowrap="false">
			<thead>
				<tr>
					<th field="id" width="100" hidden="true">id</th>
					<th field="unit_id" width="100">单位ID</th>
					<th field="inout_order_number" width="100">单据号码</th>
<!-- 					购买入库111；建账入库112； 退货入库T01； -->
					<th field="physic_in_sort" width="100">入库类型</th>
					<th field="deliverer" width="100">供货单位</th>
					<th field="physic_io_date" width="100">出入库日期</th>
					<th field="evidence" width="100">凭据说明</th>
					<th field="account_receivable" width="100">付款说明</th>
					<th field="method_of_payment" width="100">付款方式</th>
					<th field="contract_order_number" width="100">合同号</th>
					<th field="receipt_number" width="100">发票号</th>
					<th field="handle" width="100">操作员</th>
					<th field="handle_date" width="100">操作日期</th>
					<th field="account_sign" width="100">0 未入帐；1 已入帐</th>
					<th field="account_person" width="100">审核员</th>
					<th field="account_date" width="100">审核日期</th>
					<th field="tax_rate" width="100">税率</th>
					<th field="brokerage" width="100">经手人</th>
				</tr>
			</thead>
		</table>

		<!-- 按钮 -->
		<div id="toolbar">
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-reload" plain="true" onclick="reload();">刷新</a>
<!-- 			<a href="javascript:void(0);" class="easyui-linkbutton" -->
<!-- 				iconCls="icon-add" plain="true" onclick="addPsPhysicInHead();">新增</a>  -->
<!-- 			<a href="javascript:void(0);" class="easyui-linkbutton" -->
<!-- 				iconCls="icon-edit" plain="true" onclick="editPsPhysicInHead();">编辑</a>  -->
<!-- 			<a href="javascript:void(0);" class="easyui-linkbutton" -->
<!-- 				iconCls="icon-remove" plain="true" onclick="deletePsPhysicInHead();">删除</a> -->
				
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-search" plain="true" onclick="editPsPhysicInHead();">查看</a> 
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-man" plain="true" onclick="deletePsPhysicInHead();">审核</a>
			<span>用户名:</span><input name="search_username" id="search_username" value="" size=10 /> 
  			<a href="javascript:searchPsPhysicInHeadQ()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a> 
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-jright" plain="true" onclick="searchPsPhysicInHead();">更多查询</a>
		</div>

		<!-- 添加/修改对话框 -->
<!--  			buttons="#dlg_AM-buttons"  -->
		<div id="dlg" class="easyui-dialog"
			style="width:800px;height:420px;padding:0px 0px" 
			closed="true"
			data-options="onBeforeClose:function(){editIndex = undefined;}"
			>
			<form id="fm" method="post" novalidate>
				<%@include file="in/_formExamine.jsp"%>
				
			</form>
		</div>
		
		<!-- 添加/修改对话框按钮 -->
		<div id="dlg_AM-buttons">
			<a href="javascript:void(0)" class="easyui-linkbutton c6"
				iconCls="icon-ok" onclick="savePsPhysicInHead()" style="width:90px">保存</a> 
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')"
				style="width:90px">取消</a>
		</div>
		
		<!-- 删除对话框 -->
		<div id="dlg_delete" class="easyui-dialog"
			style="width:300px;height:200px;padding:30px 20px" closed="true"
			buttons="#dlg-del-buttons">
			<div class="ftitle">请谨慎操作</div>
			<form id="fmdelete" method="post" novalidate>
					<label>确定审核吗？</label>
			</form>
		</div>
		
		<!-- 删除对话框按钮 -->
		<div id="dlg-del-buttons">
			<a href="javascript:void(0)" class="easyui-linkbutton c6"
				iconCls="icon-ok" onclick="savePsPhysicInHead_del()" style="width:90px">审核</a> 
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-cancel" onclick="javascript:$('#dlg_delete').dialog('close')"
				style="width:90px">取消</a>
		</div>
		
		<!-- 查询对话框 -->
		<div id="dlgsearch" class="easyui-dialog"
			style="width:400px;height:380px;padding:30px 20px" closed="true"
			buttons="#dlg_query-buttons">
			<form id="fmsearch" method="post" novalidate>
				<label>权限:</label>  
                    <span id="span1" style="display: inline-block;"></span>  
                </div>
			</form>
		</div>
		
		<!-- 查询对话框按钮 -->
		<div id="dlg_query-buttons">
			<a href="javascript:void(0)" class="easyui-linkbutton c6"
				iconCls="icon-ok" onclick="searchPsPhysicInHead()" style="width:90px">查询</a> 
				<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-cancel" onclick="javascript:$('#dlgsearch').dialog('close')"
				style="width:90px">取消</a>
		</div>
		
	</div>
</body>
</html>
